package com.example.demo.util;

public class EndDateUtil {
    public static String getDate(String str){
        String[] str1 = str.split(" ");
        String newYear = "";
        String [] strings = str1[0].split("/",3);
        String s = strings[0];
        String charAt = String.valueOf(s.charAt(3));
        int a = Integer.parseInt(charAt);
        int day = 0;
        for (int i = 0; i < 10; i++) {
            if(a == 9){

            }
            if (i - a == 1){

                char s1 = (char)(a+'0');
                char s2 = (char)(i+'0');
                String s3 = ""+s2;
                StringBuffer stringBuffer = new StringBuffer(s);
                newYear = stringBuffer.replace(s.length()-1,s.length(),s3).toString();
                day = Integer.parseInt(strings[2])-1;
            }
        }
        String date =strings[0]+ "年"+strings[1]+"月"+strings[2]+"日"+"至"+newYear+"年"+strings[1]+"月"+day+"日";
        System.out.println(date);
        return date;
    }

    public static String getExpirationDate(String str){
        String[] str1 = str.split(" ");
        String newYear = "";
        String [] strings = str1[0].split("/",3);
        String s = strings[0];
        String charAt = String.valueOf(s.charAt(3));
        int a = Integer.parseInt(charAt);
        int day = 0;
        for (int i = 0; i < 10; i++) {
            if(a == 9){
            }
            if (i - a == 1){
                char s1 = (char)(a+'0');
                char s2 = (char)(i+'0');
                String s3 = ""+s2;
                StringBuffer stringBuffer = new StringBuffer(s);
                day = Integer.parseInt(strings[2])-1;
                newYear = stringBuffer.replace(s.length()-1,s.length(),s3).toString();
            }
        }
        String date =newYear+"/"+strings[1]+"/"+day;
        return date;
    }
}
